<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        Array.prototype.sum = function () {
            var total = 0;
            for (var i = 0; i < this.length; i++) {
                total += this[i];
            }
            return total;
        }



        function getMax(x, y, z) {
            console.log(this);
            var max = x > y ? x : y;
            max = max > z ? max : z;
            return max;
        }

        // var max=getMax(100,200,300);
        // console.log(max);

        //调用函数时，想改变函数内部this指针指向的对象，
        //必须使用call或apply来调用函数
        //第一个参数是this需要指向的对象
        var stu = {
            name: 'zhangsan'
        }
        // var n = getMax.call(stu, 100, 200, 300);

        var n = getMax.apply(stu, [100, 200, 300]);

        // var n = getMax.call(this, 100, 200, 300);
        console.log(n);
    </script>
</body>

</html>